<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="apple-mobile-web-app-title" content="阿福易购">
    <meta content="telephone=no" name="format-detection" />
    <meta content="email=no" name="format-detection" />
    <!-- uc、qq浏览器 -->
    <meta name="screen-orientation" content="portrait">
    <meta name="full-screen" content="yes">
    <meta name="browsermode" content="application">
    <meta name="x5-orientation" content="portrait">
    <meta name="x5-fullscreen" content="true">
    <meta name="x5-page-mode" content="app">
    <meta name="HandheldFriendly" content="true">
    <meta name="MobileOptimized" content="320">
    <meta name="csrf-token" content="{{ csrf_token() }}" />

    <title>商城-收货地址</title>
    <link rel="stylesheet" href="{{ asset('/build/css/app.min.css') }}">
</head>
<body ontouchstart="">


@inject('addressService','App\Interfaces\AddressService')



<?php

    //$user_id = 198859;
    $user = Auth::user();

    if($user){
        $user_id = $user->id;

        $addressService = $addressService->getAddressInfo($user_id);
    }else{

        throw new AddressException("用户user_id不能为空，请登录");
    }//end if()

?>





<footer class="ui-footer af-footer">
    <div class="ui-btn-wrap" style="margin-top: -10px;">

        <button class="ui-btn-lg"   onclick="javascript:location.href='/my/address/show'"  style="background-color: #81cac5;background-image: none;border: 1px solid #81cac5;color: #fff;">



                新建收货地址
        </button>
    </div>
</footer>

<div class="ui-container"  >

    <ul class="J-list ui-address-card">
        @if(!empty($addressInfo))

            @foreach($addressInfo as $key=>$item)
             <li class="ui-border-tb" data-id="{{$item->address_id}}">
                <h3>
                    <span class="J-item name" data-name="consignee" data-val="{{$item->consignee}}">{{$item->consignee}}</span>
                    <span class="J-item phone" data-name="mobile" data-val="{{$item->mobile}}">{{$item->mobile}}</span>
                </h3>
                <div class="address">
                    <span class="J-item" data-name="province" data-val="{{$item->province}}">{{$item->province}}</span>
                    <span class="J-item" data-name="city" data-val="{{$item->city}}">{{$item->city}}</span>
                    <span class="J-item" data-name="district" data-val="{{$item->district}}">{{$item->district}}</span>
                    <span class="J-item" data-name="address" data-val="{{$item->address}}">{{$item->address}}</span>

                    <span class="J-item af-hide" data-name="country" data-val="中国"></span>
                    <span class="J-item af-hide" data-name="position_ids" data-val="{{$item->position_ids}}"></span>

                    <span class="J-item af-hide" data-name="is_default" data-val="{{$item->is_default}}"></span>
                </div>
                <div class=" tool  ui-border-t">
                    <span class="select">
                       <label class="ui-radio">
                           <input type="radio" name="radio" @if($item->is_default) checked @endif>
                           设为默认
                       </label>
                    </span>
                    <span class="op ui-tiled">
                        <label class="J-edit" onclick="window.location.href='/my/address/{{$item->address_id}}/edit'"><i class="ui-icon-order"></i>编辑</label>
                        <label class="J-del"><i class="ui-icon-delete"></i>删除</label>
                    </span>
                </div>
            </li>

            @endforeach


        @endif
    </ul>


</div>



<script src="{{ asset('/build/lib/zepto.min.js') }}"></script>
<script src="{{ asset('/build/js/frozen.js') }}"></script>
<script src="{{ asset('/build/js/app.min.js') }}"></script>

<script type="text/javascript">

$('.J-list').on('change','.ui-radio input',function(e){
    var that=$(this).closest('li'),
        id=that.attr('data-id'),
        items=that.find('.J-item'),
        data={};

    for(var i=0;i<items.length;i++){
        var cur=$(items[i]);
        data[cur.attr('data-name')]=cur.attr('data-val');
    }
    data['is_default']=1;

    MyAjax('/my/address/'+id,'put',data,function(res){
        topTip('操作成功！');
        @if(Request::get('redirect_uri'))
            window.location.href='{{Request::get('redirect_uri')}}';
            @endif
    });
});
$('.J-list').on('click','.J-del',function(){
    var li=$(this).closest('li');

    // console.log($(this).parentNode('li'));
    var id=li.attr('data-id');
    // console.log(id)
    var dialog=$.dialog({
        title:'提示信息',
        content:'确定要删除吗？',
        button:['取消','确认']
    });

    dialog.on('dialog:action',function(e){
        if(e.index){
            MyAjax('/my/address/'+id,'delete',{'_token':_token},function(res){
                // li.fadeOut(500,function(){li.remove()});
                li.remove();
            });
        }
    });
});

</script>

</body>
</html>